﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Framework.MVC;
using Identity.Model;
using Identity.IService.Entry;
using Log.Model;
using FrontCenter.Models;
using Framework.Common.Utils;
using System.Configuration;

namespace FrontCenter.Controllers
{
    public class IdentityController : AsyncControllerBase
    {
        #region Private

        private static readonly double m_fontSize = double.Parse(ConfigurationManager.AppSettings["VerifyCodeSize"]);
        private static readonly int m_height = int.Parse(ConfigurationManager.AppSettings["VerifyCodeHeight"]);
        private static readonly double m_minutes = double.Parse(ConfigurationManager.AppSettings["VerifyCodeMinutes"]);
        private static readonly int m_length = int.Parse(ConfigurationManager.AppSettings["VerifyCodeLength"]);

        private const string m_resource = "vc00";

        private const string m_delete = "didentity";

        #endregion Private

        #region Validate

        public void ValidateAsync(string code, string resource, string source) {
            ValidateIdentityModel model = new ValidateIdentityModel {
                IdentityCode = code,
                IdentityResource = resource,
                Source = source
            };
            InitModel(model);
        }

        public ActionResult ValidateCompleted(IdentityEntry entry)
        {
            return Json(entry != null?entry.value:string.Empty);
        }

        #endregion Validate

        #region Delete

        public void DeleteAsync(string code, string resource, string source)
        {
            DeleteIdentityModel model = new DeleteIdentityModel
            {
                IdentityCode = code,
                IdentityResource = resource,
                Source = source
            };
            InitModel(model);
        }

        public ActionResult DeleteCompleted(IdentityEntry entry)
        {
            return Json(entry!=null);
        }

        #endregion Delete
    }
}
